/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 1e3;

int ecnt;
int heads[maxn * 2 + 1];

struct Edge {
  int v, nxt;
} e[maxn * maxn * 2];

inline void add(int u, int v) {
  e[++ecnt].v = v, e[ecnt].nxt = heads[u], heads[u] = ecnt;
}

int n;
int a[maxn + 1][maxn + 1];
bool r[maxn + 1], c[maxn + 1], rr[maxn + 1], cc[maxn + 1];

int deg[maxn * 2 + 1];

int row(int i) { return i; }
int col(int i) { return i + n; }

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> a[i][j];
      if (a[i][j] == -1) {
        add(row(i), col(j)), add(col(j), row(i));
        deg[row(i)]++, deg[col(j)]++;
      } else {
        rr[i] ^= a[i][j];
        cc[j] ^= a[i][j];
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    cin >> r[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
  }
  std::queue<int> q;
  for (int i = 1; i <= n * 2; ++i) {
    if (deg[i] == 1) {
      q.emplace(i);
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (!deg[u]) continue;
    deg[u] = 0;
    for (int i = heads[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      if (deg[v]) {
        deg[v]--;
        if (v > n) {
          a[u][v - n] = r[u] ^ rr[u];
          cc[v - n] ^= a[u][v - n];
        } else {
          a[v][u - n] = c[u - n] ^ cc[u - n];
          rr[v] ^= a[v][u - n];
        }
        if (deg[v] == 1) q.push(v);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (a[i][j] == -1) {
        cout << -1;
        return 0;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cout << a[i][j] << ' ';
    }
    cout << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("G. Matrix Repair.in", "r", stdin);
  freopen("G. Matrix Repair.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
